<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>编辑用户 - SimpleHire</title>
    <link
      th:href="@{/webjars/bootstrap/5.3.0/css/bootstrap.min.css}"
      rel="stylesheet"
    />
    <link th:href="@{/css/style.css}" rel="stylesheet" />
  </head>
  <body>
    <div th:replace="fragments/header :: header"></div>

    <main class="container mt-4">
      <div class="row justify-content-center">
        <div class="col-md-8">
          <div class="card">
            <div class="card-header bg-primary text-white">
              <h4 class="mb-0">编辑用户信息</h4>
            </div>
            <div class="card-body">
              <form
                th:action="@{/admin/users/update}"
                th:object="${user}"
                method="post"
              >
                <input type="hidden" th:field="*{id}" />

                <div class="row mb-3">
                  <div class="col-md-6">
                    <label for="username" class="form-label">用户名</label>
                    <input
                      type="text"
                      class="form-control"
                      id="username"
                      th:field="*{username}"
                      readonly
                    />
                  </div>
                  <div class="col-md-6">
                    <label for="email" class="form-label">邮箱</label>
                    <input
                      type="email"
                      class="form-control"
                      id="email"
                      th:field="*{email}"
                      required
                    />
                  </div>
                </div>

                <div class="row mb-3">
                  <div class="col-md-6">
                    <label for="fullName" class="form-label">姓名</label>
                    <input
                      type="text"
                      class="form-control"
                      id="fullName"
                      th:field="*{fullName}"
                    />
                  </div>
                  <div class="col-md-6">
                    <label for="phoneNumber" class="form-label">电话号码</label>
                    <input
                      type="tel"
                      class="form-control"
                      id="phoneNumber"
                      th:field="*{phoneNumber}"
                    />
                  </div>
                </div>

                <div class="mb-3">
                  <label class="form-label">用户角色</label>
                  <div class="row">
                    <div th:each="role : ${allRoles}" class="col-md-4 mb-2">
                      <div class="form-check">
                        <input
                          class="form-check-input"
                          type="checkbox"
                          th:id="'role_' + ${role}"
                          th:value="${role}"
                          name="roles"
                          th:checked="${user.roles != null && user.roles.contains(role)}"
                        />
                        <label
                          class="form-check-label"
                          th:for="'role_' + ${role}"
                          th:text="${role}"
                        ></label>
                      </div>
                    </div>
                  </div>
                </div>

                <div class="mb-3">
                  <div class="form-check form-switch">
                    <input
                      class="form-check-input"
                      type="checkbox"
                      role="switch"
                      id="isActive"
                      th:field="*{isActive}"
                    />
                    <label class="form-check-label" for="isActive"
                      >账户激活状态</label
                    >
                  </div>
                </div>

                <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                  <a th:href="@{/admin/users}" class="btn btn-secondary me-md-2"
                    >取消</a
                  >
                  <button type="submit" class="btn btn-primary">
                    保存更改
                  </button>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>
    </main>

    <div th:replace="fragments/footer :: footer"></div>

    <script
      th:src="@{/webjars/bootstrap/5.3.0/js/bootstrap.bundle.min.js}"
    ></script>
  </body>
</html>
